import Vue from 'vue'
import Vuex from 'vuex'
// import {newsOrder} from "@/api/api";

import {loginDetail} from "@/api/api";
import router from '../router'
import {Notify} from "vant";
Vue.use(Vuex)
// import {newsList} from '../api/api'
export default new Vuex.Store({
  state: {
    newList:[{name:'新闻',categoryId:2}],
    NewsId:'',
    islogin: false
  },
  mutations: {
    login(state, islogin1) {
      state.islogin = islogin1
    },
    changnewList(state, newsList) {
      state.newList = newsList
    },
    changNewsId(state,newsList){
      state.NewsId = newsList
    }
  },
  actions: {

    login(context, value) {
      loginDetail(value.username, value.password, value.rememberMe).then(res => {
        console.log(res)
        if(res.code==0){
          context.commit('login',true);
          Notify({ type: 'success', message: '登陆成功' });
          router.push('/index')
        }else {
          Notify({ type: 'danger', message: '账号或密码错误' });
        }
      })

      // getnewsList(context) {
      //   newsList().then(res => {
      //     console.log(res)
      //     context.commit("changenewList", res.rows)
      //   })
      // }
    },
  },
  modules: {}
})